<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../js/vue-2.6.12.js"></script>
  
</head>
<body>
  <div id="app">
    <div style="margin:0 auto;width:400px;" >
      Add a todo :<input type="text" v-model="todo"/><button @click="addList">Add</button>
      <ul v-if="todoList.length>0">
        <li v-for="(item,index) in todoList" :key="index">{{item}} <button @click="removeList(index)">Remove</button></li>
      </ul>
      <h1 v-else>暂无待办事宜！</h1>
    </div>
  </div>
  <script type="text/javascript">
    const vm = new Vue({
      el:"#app",
      data:{
        todoList:["做算法题"],
        todo:""
      },
      methods:{
        removeList:function(index){
          this.todoList.splice(index,1);
        },
        addList:function(){
          this.todoList.push(this.todo);
        }
      }
    });

  </script>
</body>
</html>